package com.example.petplatform.controller;

import com.example.petplatform.common.Result;
import com.example.petplatform.entity.PetTypes;
import com.example.petplatform.entity.Param.Params;
import com.example.petplatform.service.PetTypesService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宠物类别管理接口
 */
@RestController
@RequestMapping("/types")
public class PetTypesController {
    @Resource
    private PetTypesService petTypesService;

    // 获取所有宠物类别信息
    @GetMapping("/all")
    public Result getAllTypes() {
        List<PetTypes> list = petTypesService.getAllTypes();
        return Result.success(list);
    }

    // 分页查询宠物类别
    @GetMapping("/search")
    public Result getSearch(Params params) {
        PageInfo<PetTypes> list = petTypesService.getSearch(params);
        return Result.success(list);
    }

    // 添加或修改宠物类别信息
    @PostMapping("/add")
    public Result addType(@RequestBody PetTypes petType) {
        if (petType.getId() == null) {
            // 添加数据
            List<PetTypes> list = petTypesService.addType(petType);
            return Result.success(list);
        } else {
            // 修改数据
            List<PetTypes> list = petTypesService.updateType(petType);
            return Result.success(list);
        }
    }

    // 删除宠物类别信息
    @DeleteMapping("/delete")
    public Result deleteType(@RequestBody PetTypes petType) {
        List<PetTypes> list = petTypesService.deleteType(petType.getId());
        return Result.success(list);
    }
}
